# coding: utf-8
# 查找 gitlab Team-iOS-Platform 中的所有 'ZH' 开头的 repo，以 podfile 可以引用的形式打印出来
require 'gitlab'

Gitlab.configure do |config|
  config.endpoint       = 'https://git.in.zhihu.com/api/v4' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
  config.private_token  = '9sZyNL4zzXeQjy-9GjSt'       # user's private token or OAuth2 access token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
end

projects = Gitlab.group_projects(879).sort_by { |p| p.name }

podspec = projects.map { |p|
  tag = Gitlab.tags(p.id).first
  if tag
    """
# #{p.description}
pod \'#{p.name}\', :git => \'#{p.ssh_url_to_repo}\', :tag => \'#{tag.name}\', :inhibit_warnings => false
    """
  else
    """
# #{p.description}
pod \'#{p.name}\', :git => \'#{p.ssh_url_to_repo}\', :inhibit_warnings => false
    """
  end
}.join("")

readme = """
# pod template

Pod template for Zhihu iOS team.

## current version

(如需更新，请在根目录执行 `ruby setup/README_update.rb`)

```ruby
#{podspec}
```
"""

File.open(File.expand_path("../../README.md", __FILE__), "w") do |f|
  f.puts readme
end
